#include "IconBar.hpp"
#include "MainView.hpp"
#include "FL/Fl_Button.H"
#include "constants.hpp"
using namespace m3g_viewer;

static void callback_show_tree_view   (Fl_Window* w, void* v);
static void callback_show_object_view (Fl_Window* w, void* v);
static void callback_open_file_dialog (Fl_Window* w, void* v);


IconBar:: IconBar (MainView* view) : Fl_Group(ICON_BAR_X,
                                              ICON_BAR_Y,
                                              ICON_BAR_WIDTH,
                                              ICON_BAR_HEIGHT),
                                     main_view(view)
{
    int x = ICON_BAR_X;
    int y = ICON_BAR_Y;

    Fl_Button* btn0 = new Fl_Button (x + ICON_MARGIN,
                                     y + ICON_MARGIN,
                                     ICON_REAL_WIDTH,
                                     ICON_REAL_HEIGHT,
                                     "T");
    btn0->callback ((Fl_Callback*)callback_show_tree_view  , main_view);
    btn0->box (FL_THIN_UP_BOX);
    x += ICON_WIDTH;

    Fl_Button* btn1 = new Fl_Button (x + ICON_MARGIN,
                                     y + ICON_MARGIN,
                                     ICON_REAL_WIDTH,
                                     ICON_REAL_HEIGHT,
                                     "O");
    btn1->callback ((Fl_Callback*)callback_show_object_view, main_view);
    btn1->box (FL_THIN_UP_BOX);
    x += ICON_WIDTH;

    Fl_Button* btn2 = new Fl_Button (x + ICON_MARGIN,
                                     y + ICON_MARGIN,
                                     ICON_REAL_WIDTH,
                                     ICON_REAL_HEIGHT,
                                     "F");
    btn2->callback ((Fl_Callback*)callback_open_file_dialog, main_view);
    btn2->box (FL_THIN_UP_BOX);

    end ();
    box (FL_THIN_UP_BOX);

    resizable (0);
}

IconBar:: ~IconBar ()
{

}

static
void callback_show_tree_view (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->show_tree_view ();
}

static
void callback_show_object_view (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->show_object_view (NULL);
}

static
void callback_open_file_dialog (Fl_Window* w, void* v)
{
    MainView* view = (MainView*)v;
    view->open_file_dialog ();
}

